<?php
defined('IN_IXDCW') or exit('Access Denied');
$menus = array (
    array('车主圈列表', '?moduleid='.$moduleid.'&file='.$file),
);
$this_forward = '?moduleid='.$moduleid.'&file='.$file;

$options = array();
if(in_array($action, array(''))) {
	$pagesize  = (isset($psize) && !empty($psize)) ? intval($psize) : 20;
}
switch($action) {
	case 'view':
		$username or msg(ERR_MSG);
		$item = DbOwners::find($username);
		if($item->amid) {
			$amids = explode(',',$item->amid);
			$autoModels = array();
			foreach($amids as $amid) {
				$model = DbAutoModel::find($amid);
				$brand = DbAutoCategory::find($model->arbid);
				$autoModels[] = $brand->name.'-'.$model->name;
			}

		}
		include tpl('owner_view', 'member');
		break;
	case 'delete';
		$username or msg(ERR_MSG);
		$item = DbOwners::find($username);
		!$item->delete() or msg('删除成功', Env::referer());
	default:

		$count = DbOwners::count();

		// pagination
		$pn = new Pagination();
		$pn->recordsPerPage($pagesize);
		$pn->records($count);

		// options
		$options['order'] = 'edittime DESC';
		$options['limit'] = $pagesize;
		$options['offset'] = ($pn->getPage()-1) * $options['limit'];

		$lists = DbOwners::find('all',$options);
		include tpl('owner', 'member');
	break;
}